package edu.pmfbl.mnr.sem.mcmatm.gui;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import edu.pmfbl.mnr.sem.mcmatm.app.*;

/**
 * <p>Title: MCMA Test Maker</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2009</p>
 *
 * <p>Company: KrndijaSoft</p>
 *
 * @author Ninoslav Krndija
 * @version 1.0
 */
public class MainFrame extends JFrame
{
  private static MainFrame mainFrame = null;

  AppDataModule appDataModule;
  PitanjeInfoPanel pitanjeInfoPanel;
  PitanjeNavPanel pitanjeNavPanel;

  /**
   * Vraca jedinstvenu instancu objekta MainFrame za cijelu aplikaciju.
   * Takodje pakuje i centrira frame.
   *
   * @return instanca MainFrame
   */
  public static MainFrame getInstance()
  {
    if(mainFrame == null)
      mainFrame = new MainFrame();

    return mainFrame;
  }

  // Konstruktor
  public MainFrame()
  {
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    };
  }

  public void addNotify()
  {
    super.addNotify();
    mainFrame.pack();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = this.getSize();
    if(frameSize.height > screenSize.height)
      frameSize.height = screenSize.height / 2;
    if(frameSize.width > screenSize.width)
      frameSize.width = screenSize.width;
    mainFrame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    mainFrame.setSize(frameSize.width, frameSize.height);
  }

  /**
   * Contains component initialization code generated by the visual designer.
   *
   * @throws Exception exception
   */
  public void jbInit() throws Exception
  {
    appDataModule = AppDataModule.getDataModule();
    pitanjeInfoPanel = PitanjeInfoPanel.getPitanjeInfoPanel();  //pitanjeInfoPanel = new PitanjeInfoPanel();
    pitanjeNavPanel = new PitanjeNavPanel();

    BorderLayout borderLayout = new BorderLayout();
    this.getContentPane().setLayout(borderLayout);

    this.getContentPane().add(pitanjeInfoPanel, java.awt.BorderLayout.NORTH);
    this.getContentPane().add(pitanjeNavPanel, java.awt.BorderLayout.CENTER);

    this.setResizable(false);
    this.setTitle("MCMA Test Maker");
    this.setSize(new Dimension(502, 428));
  }

  protected void processWindowEvent(WindowEvent e)
  {
    if(e.getID() == WindowEvent.WINDOW_CLOSING)
    {
      //appDataModule.resolveData();
      this.dispose();
      System.exit(0);
    }
  }

}
